'''
Created on Mar 30, 2013

@author: drelfi
'''
import unittest
import analyze

class TestAnalyze(unittest.TestCase):


    def setUp(self):
        self.s1 = str("This is a sample text\nOnly 2 lines")
        self.s3 = str("This is a sample text\nOnly two lines")
        self.s4 = str("This is some sample text\nOnly two lines")
        self.s2 = str("This is a longer text\nAt least 3 lines\nmultiples repetitions\nAt least 3 lines")
        

    def tearDown(self):
        pass


    def testCompareSimilarInput(self):
        #if uses the same lines to compare
        
        #when
        result = analyze.matchingString(self.s1, self.s1)
        
        #then
        self.assertTrue(result == self.s1, "Failed to create a difference from the same line")

    def testCompareDifferentInput(self):
        #if
        #when
        result = analyze.matchingString(self.s1, self.s2)
        
        #then
        self.assertTrue(result == "This is a le text\nl  lines", "Failed to create a difference from different lines")

    def testSequenceMatchingInvalidType(self):
        #if
        #when
        s = analyze.matchingStringSequence(None)
        
        #then
        self.assertEqual(s, "", "Non empty string because of non sequence type as input")

    def testSequenceMatching2Elements(self):
        #if
        seq = [self.s1, self.s3]
        
        #when
        s = analyze.matchingStringSequence(seq)
        
        #then
        self.assertEqual(s, "This is a sample text\nOnly  lines", "Equal area has not been identified")

    def testSequenceMatching3DifferentElements(self):
        #if
        seq = [self.s1, self.s3, self.s4]
        
        #when
        s = analyze.matchingStringSequence(seq)
        
        #then
        self.assertEqual(s, "This is  sample text\nOnly  lines", "Equal area has not been identified")

    def testSequenceMatching3EqualtElements(self):
        #if
        seq = [self.s1, self.s1, self.s1]
        
        #when
        s = analyze.matchingStringSequence(seq)
        
        #then
        self.assertEqual(s, "This is a sample text\nOnly 2 lines", "Equal area has not been identified")

    def testSequenceMatchingParallel3DifferentElements(self):
        #if
        seq = [self.s1, self.s3, self.s4]
        
        #when
        s = analyze.matchingStringSequenceParallel(seq)
        
        #then
        self.assertEqual(s, "This is  sample text\nOnly  lines", "Equal area has not been identified")

    def testSequenceMatchingParallel3EqualtElements(self):
        #if
        seq = [self.s1, self.s1, self.s1]
        
        #when
        s = analyze.matchingStringSequenceParallel(seq)
        
        #then
        self.assertEqual(s, "This is a sample text\nOnly 2 lines", "Equal area has not been identified")

    def testSequenceMatchingParallel9EqualtElements(self):
        #if
        seq = [self.s1, self.s1, self.s1, self.s1, self.s1, self.s1, self.s1, self.s1, self.s1]
        
        #when
        s = analyze.matchingStringSequenceParallel(seq)
        
        #then
        self.assertEqual(s, "This is a sample text\nOnly 2 lines", "Equal area has not been identified")

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()